import { BasicColumn } from '/@/components/Table';
import { render } from '/@/utils/common/renderUtils';
import { useI18n } from '/@/hooks/web/useI18n';
import { FormSchema } from '/@/components/Table';
const { t } = useI18n('asset.inventoryManagement.fields');
const { t: common } = useI18n('common');
const { t: asset } = useI18n('asset.assetInfo.fields');
const inventoryField = {
  inventoryNumber: t('inventory_number'),
  inventoryName: t('inventory_name'),
  checkState: t('check_state'),
  inventoryState: t('inventory_state'),
  inventoryWay: t('inventort_way'),
  notes: t('notes'),
  inventoryPerson: t('inventory_person'),
  inventoryTime: t('inventoryTime'),
  createTime: t('createTime'),
  createBy: t('createBy'),
  inventory_type: t('inventory_type'),
  count: t('count'),
  actualCount: t('actualCount'),
  actualPosition: t('actualPosition'),
  difference: t('difference'),
};
//列表数据
export const columns: BasicColumn[] = [
  {
    title: inventoryField.inventoryNumber,
    align: 'center',
    dataIndex: 'inventoryNumber',
    fixed: 'left',
  },
  {
    title: inventoryField.inventoryName,
    align: 'center',
    dataIndex: 'inventoryName',
    fixed: 'left',
  },
  {
    title: inventoryField.inventoryState,
    align: 'center',
    dataIndex: 'inventoryState',
    customRender: ({ text }) => {
      if (text === '1') {
        return '未盘点';
      } else if (text === '2') {
        return '已盘点';
      }
    },
  },
  {
    title: inventoryField.createBy,
    align: 'center',
    dataIndex: 'createBy',
  },
  {
    title: inventoryField.createTime,
    align: 'center',
    dataIndex: 'createTime',
  },
  {
    title: inventoryField.inventoryPerson,
    align: 'center',
    dataIndex: 'inventoryPerson',
  },
  {
    title: inventoryField.inventoryTime,
    align: 'center',
    dataIndex: 'inventory_task.createTime',
  },
  // {
  //   title: asset('useState'),
  //   align: 'center',
  //   dataIndex: 'useState',
  // },
  // {
  //   title: asset('user'),
  //   align: 'center',
  //   dataIndex: 'user',
  // },
  // {
  //   title: asset('custodyDepartment'),
  //   align: 'center',
  //   dataIndex: 'custodyDepartment',
  // },
  // {
  //   title: asset('cartegory'),
  //   align: 'center',
  //   dataIndex: 'cartegory',
  // },
  // {
  //   title: asset('code'),
  //   align: 'center',
  //   dataIndex: 'code',
  // },
  // {
  //   title: inventoryField.count,
  //   align: 'center',
  //   dataIndex: 'count',
  // },
  // {
  //   title: inventoryField.actualCount,
  //   align: 'center',
  //   dataIndex: 'actualCount',
  // },
  // {
  //   title: inventoryField.difference,
  //   align: 'center',
  //   dataIndex: 'difference',
  // },
  // {
  //   title: inventoryField.actualPosition,
  //   align: 'center',
  //   dataIndex: 'actualPosition',
  // },
];
//查询数据
export const searchFormSchema: FormSchema[] = [
  {
    label: inventoryField.inventoryNumber,
    field: 'inventoryNumber',
    component: 'Input',
  },
  {
    label: inventoryField.createTime,
    field: 'createTime',
    component: 'RangePicker',
  },
];
//表单数据
export const formSchema: FormSchema[] = [
  {
    label: inventoryField.inventoryName,
    field: 'inventoryName',
    component: 'Input',
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.inventoryName }];
    },
  },
  {
    label: inventoryField.inventory_type,
    field: 'inventoryType',
    component: 'RadioGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '全盘', value: '1' },
        { label: '数量管控', value: '2' },
        { label: '条码管控', value: '3' },
      ],
    },
  },
  {
    label: inventoryField.inventoryWay,
    field: 'inventortWay',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'inventoryWay',
      showChooseOption: false,
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.inventoryWay }];
    },
  },
  {
    label: asset('position'),
    field: 'position_name',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
  },
  {
    label: inventoryField.createBy,
    field: 'inventoryPerson',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',
    },
    dynamicRules: () => {
      return [{ required: true, message: common('inputText') + inventoryField.createBy }];
    },
  },
  {
    label: asset('cartegory'),
    field: 'category_name',
    component: 'JTreeSelect',
    componentProps: { dict: 'asset_category,category_name,id', pidField: 'pid', pidValue: '0', hasChildField: 'has_child' },
  },
  {
    label: asset('useState'),
    field: 'use_state',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'useState',
    },
  },
  {
    label: t('useDepartment'),
    field: 'departmentId',
    component: 'JSelectDept',
  },
  {
    label: t('user'),
    field: 'user',
    component: 'JSelectUserByDept',
    componentProps: {
      labelKey: 'realname',
    },
  },
  {
    label: asset('description'),
    field: 'notes',
    component: 'Input',
  },
  // TODO 主键隐藏字段，目前写死为ID
  {
    label: '',
    field: 'id',
    component: 'Input',
    show: false,
  },
];
//盘点界面数据
export const inventoryformSchema: FormSchema[] = [
  {
    label: inventoryField.inventoryName,
    field: 'inventoryName',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: inventoryField.inventoryNumber,
    field: 'inventoryNumber',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },

  {
    label: inventoryField.createBy,
    field: 'createBy',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: inventoryField.createTime,
    field: 'createTime',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: inventoryField.inventoryState,
    field: 'inventoryState',
    component: 'JDictSelectTag',
    componentProps: {
      dictCode: 'inventoryState',
    },
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: asset('cartegory'),
    field: 'category_name',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: asset('name'),
    field: 'name',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: asset('code'),
    field: 'code',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: asset('useState'),
    field: 'useState',
    component: 'Input',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: inventoryField.actualPosition,
    field: 'actualPostion',
    component: 'JTreeSelect',
    componentProps: {
      dict: 'asset_position,position_name,id',
      pidField: 'pid',
      pidValue: '0',
      hasChildField: 'has_child',
    },
  },
  {
    label: inventoryField.count,
    field: 'count',
    component: 'InputNumber',
    colProps: { span: 12 },
    dynamicDisabled: true,
  },
  {
    label: inventoryField.actualCount,
    field: 'actualCount',
    component: 'InputNumber',
    colProps: { span: 12 },
  },
  {
    label: inventoryField.difference,
    field: 'difference',
    component: 'InputNumber',
    colProps: { span: 12 },
  },
];
/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
